package com.spring.ioc;

import com.spring.lifecycle.config.MainConfigOfProfile;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.sql.DataSource;

public class IOCTest_Profile {
    private AnnotationConfigApplicationContext applicationContext;

    @Test
    public void test00() {
        applicationContext = new AnnotationConfigApplicationContext(MainConfigOfProfile.class);
        printNames();
        applicationContext.close();
    }

    public void printNames() {
        String[] names = applicationContext.getBeanNamesForType(DataSource.class);
        for (String name : names) {
            System.out.println(name);
        }
    }
    @Test
    public void test01() {
        applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.getEnvironment().setActiveProfiles("dev", "test");
        applicationContext.register(MainConfigOfProfile.class);
        applicationContext.refresh();

        printNames();

        applicationContext.close();
    }


}

